package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domin.Teacher;

public class TeacherDao {
    private static Teacher[] teachers=new Teacher[10];

    //添加
    public boolean addTtudent(Teacher teacher){
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher1 = teachers[i];
            if (teacher1==null){
                teachers[i]=teacher;
                return true;
            }
        }
        return false;
    }
    //查看
    public Teacher[] findAllTeacher() {
        return teachers;
    }
    //删除
    public void deleteTeacher(String sid) {
        int getindex = getindex(sid);
        teachers[getindex]=null;
    }
    //修改
    public void updateTeacher(String sid, Teacher teacher) {
        int getindex = getindex(sid);
        teachers[getindex]=teacher;
    }

    //根据索引找工号
    public int getindex(String sid){
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if (teacher!=null&&teacher.getSid().equals(sid)){
                return i;
            }
        }
        return -1;
    }
}
